import roslibpy
import roslibpy.actionlib

class Action:

    def __init__(self, framework):
        self.framework = framework
        self.action_client = None
        self.action_client_goal = None
        self.action_id = 2
        self.result = 0

    def set(self, action_id):
        self.action_id = action_id
        # 0为紧急停止，这里不做使用
        if self.action_id > 0:
            self.do()

    def do(self):
        if self.framework.framework.utils.device.device_state:
            self.action_client = roslibpy.actionlib.ActionClient(self.framework.framework.utils.device.device_connect, "/alphadog_node/do_action", "ros_alphadog/DoAction")
            self.action_client_goal = roslibpy.actionlib.Goal(self.action_client, roslibpy.Message({"action_id": self.action_id}))
            self.action_client_goal.send()
            result = self.action_client_goal.wait(10)
            self.action_client.dispose()
            self.action_id = 2
            self.result = result
